import {
	mapMutations
} from 'vuex'
export default {
	...mapMutations([
		'upUserInfo'
	]),
	getUserInfo() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'getLoginUser',
			params: {
	
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.upUserInfo(res.data)
				} else {
					that.upUserInfo({})
				}
			}
		})
	},
	upAvatar() {
		let that = this
		that.$httpRequest.handlerUploadPic(res => {
			if (res.code === that.$httpConfig.SUCCESS_CODE) {
				let avatar = res.data.filePath
				that.$httpRequest.request({
					that: that,
					url: 'sysUser/updateAvatar',
					params:{
						avatar:res.data.id,
						id:that.userInfo.id
					},
					success: res => {
						that.$toast.alert({
							content: res.message,
							callback: result => {
				
							}
						})
						if (res.code === that.$httpConfig.SUCCESS_CODE) {
							that.userInfo.avatarUrl = avatar
							that.upUserInfo(that.userInfo)
						} else {
				
						}
					}
				})
			}
		})
	},
	
	toReset() {
		let that = this
		if (that.atLoading) {
			//禁止多次点击
			return false
		}
		that.atLoading = true
		let emailLogin = that.userInfo.email;
		if(emailLogin){
			uni.navigateTo({
				url: '/pages/publics/emailReset'
			})
			
		}else{
			uni.navigateTo({
				url: '/pages/publics/reset'
			})
		}
		
		setTimeout(()=>{ //延时指定时间后，再解冻
			that.atLoading = false;
		}, 1000);
		
	},
	toAboutUs(){
		uni.navigateTo({
			url: '/pages/my/aboutUs'
		})
	},
	toEditMobile() {
		let that = this
		if (that.atLoading) {
		    //禁止多次点击
		    return false
		}
		that.atLoading = true
		uni.navigateTo({
			url: '/pages/my/editMobile'
		})
		setTimeout(()=>{ //延时指定时间后，再解冻
		    that.atLoading = false;
		}, 1000);
		
	},
	logout() {
		let that = this
		that.$toast.confirm({
			content: '确定要退出登录吗？',
			callback: result => {
				if (result) {
					// uni.removeStorageSync('token');
					uni.clearStorageSync()
					that.$toast.alert({
						content: '退出登录成功',
						callback: res => {
							if (res.confirm) {
								uni.navigateTo({
									url:'/pages/publics/login'
								})
							}
						}
					})
				}
			}
		})
	}
}
